package com.own.business.question.open;

import com.own.business.question.business.service.PracticeHistoryService;
import com.own.business.question.business.service.PracticeService;
import com.own.business.question.business.service.QuestionService;
import com.own.business.question.entity.bo.PracticeBo;
import com.own.business.question.entity.map.PracticeMapVo;
import com.own.business.question.entity.model.PracticeConfig;
import com.own.business.question.entity.open.BaseOpenPractice;
import com.own.business.question.entity.po.Practice;
import com.own.business.question.entity.query.PracticeQuery;
import com.own.business.question.entity.vo.PracticeVo;
import com.own.business.question.entity.vo.QuestionVo;
import com.own.component.common.base.open.api.BaseOpenMethod;
import com.own.component.common.model.R;
import com.own.component.common.model.ResultModel;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * PracticeOpenMethod
 *
 * @author 陈学礼 （你是一段成熟的代码，要学会自己改bug）
 * @version 4.0.0
 * @date 2021/5/15 9:31
 * @since 4.0.0
 */
@Component
public class PracticeOpenMethod extends BaseOpenMethod<
        Practice,
        PracticeBo,
        PracticeVo,
        PracticeMapVo,
        PracticeQuery,
        PracticeService
        > implements BaseOpenPractice {

    @Resource
    private PracticeService practiceService;
    @Resource
    private PracticeHistoryService practiceHistoryService;

    @Resource
    private QuestionService questionService;

    /**
     * 获取练习题目
     *
     * @param targetId 目标id
     * @param userId   获取题目的用户id
     * @param config   练习配置
     * @return 练习信息
     */
    @Override
    public ResultModel<PracticeVo> getPractice(Long targetId, Long userId, PracticeConfig config) {
        return R.success(practiceService.getPractice(targetId, userId, config));
    }

    /**
     * 确认提交练习
     *
     * @param practiceId 练习id
     * @return 练习信息
     */
    @Override
    public ResultModel<PracticeVo> checkPractice(Long practiceId) {
        return R.success(practiceService.checkPractice(practiceId));
    }

    /**
     * 根据流水id获取题目信息
     *
     * @param historyId 流水id
     * @return 题目信息
     */
    @Override
    public ResultModel<QuestionVo> getQuestionByHistoryId(Long historyId) {
        return R.success(questionService.getByHistoryId(historyId));
    }

    /**
     * 提交答案
     *
     * @param pk      流水id
     * @param answer  答案信息
     * @param useTime 用时
     * @return 是否提交成功
     */
    @Override
    public ResultModel<Boolean> submit(Long pk, String answer, Long useTime) {
        return R.success(practiceHistoryService.submit(pk, answer, useTime));
    }

}
